<template>

	<view class="content">

		<u-alert title="修改后务必保存才生效,点击下方步进器的数字可自定义" type="error"></u-alert>
		
		<view class="item">
			<u-icon label="实时跳动至人数第?的房间" size="40" name="/static/balance.png"></u-icon>
			<u-switch v-model="is_skip_number" @change="roomNumberSwitch"></u-switch>
			<view>
				-{{skip_number}}-
			</view>
			<u-number-box button-size="40" v-model="skip_number" integer min="1" max="5"></u-number-box>
		</view>

		<view class="item">
			<u-icon label="实时跳动至珍珠第?的房间" size="40" name="/static/balance.png"></u-icon>
			<u-switch v-model="is_skip_betting" @change="roomBettingSwitch"></u-switch>
			<view>
				-{{skip_betting}}-
			</view>
			<u-number-box button-size="40" v-model="skip_betting" integer min="1" max="5"></u-number-box>
		</view>

		<u-alert title="开启跳动后则算法预测失效,可随意选" type="success"></u-alert>

		<view class="item1">
			<view>
				<u-icon label="选择算法" size="40" name="/static/balance.png"></u-icon>
			</view>
			<view>
				--{{methodName}}--
			</view>
			<view style="width: 30%">
				<u-button color="linear-gradient(to right, rgb(66, 83, 216), rgb(213, 51, 186))"
					@click="selectMethod">选择预测</u-button>
			</view>
		</view>

		<view class="item">
			<u-icon label="连败停止" size="40" name="/static/balance.png"></u-icon>
			<view>
				--{{continue_fail}}--
			</view>
			<u-number-box button-size="40" v-model="continue_fail" integer min="1" max="1000"></u-number-box>
		</view>

		<view class="item">
			<u-icon label="连胜停止" size="40" name="/static/balance.png"></u-icon>
			<view>
				--{{wincount_stop}}--
			</view>
			<u-number-box button-size="40" v-model="wincount_stop" integer min="1" max="1000"></u-number-box>
		</view>

		<view class="item">
			<u-icon label="亏本停止" size="40" name="/static/balance.png"></u-icon>
			<view>
				--{{lose}}--
			</view>
			<u-number-box button-size="40" v-model="lose" integer min="1" max="100000"></u-number-box>
		</view>


		<view class="item">
			<u-icon label="盈利停止" size="40" name="/static/balance.png"></u-icon>
			<view>
				--{{profit}}--
			</view>
			<u-number-box button-size="40" v-model="profit" integer min="1" max="1000000"></u-number-box>
		</view>

		<u-alert title="失败后跳过设定的把数" type=""></u-alert>
		<view class="item">
			<u-icon label="失败后跳过" size="40" name="/static/balance.png"></u-icon>
			<view>
				--{{continue_fail_skip}}--
			</view>
			<u-number-box button-size="40" v-model="continue_fail_skip" integer min="0" max="10"></u-number-box>
		</view>


		<u-alert title="失败后下注(下注大小*倍数^连败)" type=""></u-alert>

		<view class="item">
			<u-icon label="下注大小" size="40" name="/static/balance.png"></u-icon>
			<view>
				--{{size}}--
			</view>
			<u-number-box button-size="40" v-model="size" integer min="1" max="1000"></u-number-box>
		</view>
		<view class="item">
			<u-icon label="倍投倍数" size="40" name="/static/balance.png"></u-icon>
			<view>
				--{{multiple}}--
			</view>
			<u-number-box button-size="40" v-model="multiple" integer min="1" max="100"></u-number-box>
		</view>
		<u-alert title="倍投连败后,继续倍投,超过设定倍投停止后重置初始值" type=""></u-alert>

		<view class="item">
			<u-icon label="倍投停止" size="40" name="/static/balance.png"></u-icon>
			<view>
				--{{multiple_reset}}--
			</view>
			<u-number-box button-size="40" v-model="multiple_reset" integer min="1" max="100"></u-number-box>
		</view>
	
		<view class="button">
			<u-button color="linear-gradient(to right, rgb(66, 83, 216), rgb(213, 51, 186))"
				@click="goBack">不修改返回</u-button>
		</view>
		<view class="button">
			<u-button color="linear-gradient(to right, rgb(66, 83, 216), rgb(213, 51, 186))"
				@click="saveSetting">保存配置</u-button>
		</view>
		<u-picker :show="show" :columns="columns" @confirm="confirm" @cancel="cancel"></u-picker>
	</view>


</template>

<script>
	import url from "../../js/url.js"
	export default {
		data() {
			return {
				is_skip_betting: false,
				is_skip_number: false,
				skip_number: 1,
				skip_betting: 1,
				methodName: null,
				show: false,
				columns: [],
				allMethod: [],
				token: null,
				size: null,
				user_id: null,
				multiple: null,
				profit: null,
				lose: null,
				wincount_stop: null,
				continue_fail: null,
				continue_fail_skip: null,
				multiple_reset: null,
			}
		},
		onLoad(option) {
			const value = uni.getStorageSync('token');
			this.token = value
			const user_id = uni.getStorageSync('userId');
			this.user_id = user_id

			//查询原来的配置
			uni.showLoading({
				title: '加载中'
			});
			uni.request({
				url: 'http://' + url + '/autoplay/autoconfig?user_id=' + this.user_id,
				header: {
					//自定义请求头信息
					'authentication': this.token
				},
				success: (res) => {
					if (res.data.data.is_skip_betting === 1) {
						this.is_skip_betting = true
					} else {
						this.is_skip_betting = false
					}
					if (res.data.data.is_skip_number === 1) {
						this.is_skip_number = true
					} else {
						this.skip_number = false
					}
					this.skip_number = res.data.data.skip_number
					this.skip_betting = res.data.data.skip_betting
					this.size = res.data.data.size
					this.methodName = res.data.data.prediction_name
					this.multiple = res.data.data.multiple
					this.profit = res.data.data.profit
					this.lose = res.data.data.lose
					this.wincount_stop = res.data.data.wincount_stop
					this.continue_fail = res.data.data.continue_fail
					this.continue_fail_skip = res.data.data.continue_fail_skip
					this.multiple_reset = res.data.data.multiple_reset
					uni.hideLoading()
				}
			})


		},
		methods: {
			roomNumberSwitch(e) {
				this.is_skip_number = e
				if (this.is_skip_number && this.is_skip_betting) {
					this.is_skip_number = e
					this.is_skip_betting = !e
				}

			},
			roomBettingSwitch(e) {
				this.is_skip_betting = e
				if (this.is_skip_betting && this.is_skip_number) {
					this.is_skip_number = !e
					this.is_skip_betting = e
				}
			},
			goBack() {
				uni.navigateBack()
			},
			saveSetting() {
				//发起网络请求
				uni.request({
					url: 'http://' + url + '/autoplay/autoconfig',
					header: {
						//自定义请求头信息
						'authentication': this.token
					},

					method: 'PUT',
					data: {
						is_skip_betting: this.is_skip_betting,
						skip_betting: this.skip_betting,
						is_skip_number: this.is_skip_number,
						skip_number: this.skip_number,
						user_id: this.user_id,
						size: this.size,
						multiple: this.multiple,
						profit: this.profit,
						lose: this.lose,
						wincount_stop: this.wincount_stop,
						continue_fail: this.continue_fail,
						continue_fail_skip: this.continue_fail_skip,
						multiple_reset: this.multiple_reset,
						prediction_name: this.methodName
					},
					success: (res) => {
						uni.navigateBack()
					}
				})

			},
			// 回调参数为包含columnIndex、value、values
			confirm(e) {
				var index = e.value[0].indexOf(" ")
				this.methodName = e.value[0].substr(0, index)
				this.show = false
			},
			cancel() {
				this.show = false
			},
			confirm1(e) {
				this.show1 = false
				this.size = e.value[0]
			},
			cancel1() {
				this.show1 = false
			},
			selectSize() {

				this.show1 = true

			},
			/**
			 * 需要将用户的id也发送上来
			 */
			selectMethod() {
				this.columns = []
				this.allMethod = []
				uni.request({
					url: 'http://' + url + '/prediction/name?user_id=' + this.user_id,
					header: {
						//自定义请求头信息
						'authentication': this.token
					},
					success: (res) => {
						for (let item in res.data.data) {
							this.allMethod.push(res.data.data[item].name + " 胜率" + res.data.data[item]
								.win_percentage+"%")
						}
						this.columns.push(this.allMethod)
					}
				});
				this.show = true

			},
		}
	}
</script>

<style>
	.solid_class {
		width: 70%;
		height: 100rpx;
	}

	.item1 {
		margin-top: 10rpx;
		width: 100%;
		height: 70rpx;
		color: black;
		margin: 10rpx;
		display: flex;
		justify-content: space-evenly;
		align-items: center;
		background-color: #71d5a1;
		border-radius: 30rpx;
	}

	.button {
		width: 100%;
		display: flex;
		flex-wrap: wrap;
		justify-content: center;
		align-items: center;
		margin: 5rpx;
	}

	.item {
		margin-top: 10rpx;
		width: 100%;
		height: 80rpx;
		color: black;
		margin: 10rpx;
		display: flex;
		justify-content: space-evenly;
		align-items: center;
		background-color: #71d5a1;
		border-radius: 30rpx;
	}

	.content {
		display: flex;
		flex-wrap: wrap;
		justify-content: center;
		align-items: center;
	}
</style>